<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/25
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms2.0/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms2.0/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms2.0/layui_ext/dtree/font/dtreefont.css">
</head>
<body class="childrenBody">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>

<form class="layui-form" method="post" id="searchFrm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">登录名称:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="loginname" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录名称" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">登录IP:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="loginip" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录IP" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">开始时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="logintime1" id="logintime1"  autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入开始时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="logintime2" id="logintime2"  autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入结束时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <button  class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm" lay-submit  lay-filter="doSearch">查询
            </button>
            <button type="reset" class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm">重置
            </button>
        </div>
    </div>
</form>

<table id="logTable" lay-filter="logTable"></table>

<script id="toolbarLog" type="text/html">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="delBatch">批量删除</button>
    </div>
</script>

<script id="barLog" type="text/html">
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">删除</a>
</script>
<!-- 添加和修改的弹出层结束 -->
<div style="display: none;padding: 20px" id="roleDiv">
    <ul id="demoTree" class="dtree" data-id="0"></ul>
</div>

<script src="${pageContext.request.contextPath}/static/layuicms2.0/layui/layui.js"></script>
    <script>
        var logTree;
        var logTable;
        var miniIndex;
        var url;
        var demoTree;
        layui.extend({
            dtree: '${pageContext.request.contextPath}/static/layuicms2.0/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
        }).use(['table','form','layer','jquery','dtree','laydate'], function(){
            var table = layui.table
            var form = layui.form
            var layer = layui.layer
            var $ = layui.jquery
            var dtree = layui.dtree
            var laydate = layui.laydate

            //执行一个laydate实例
            laydate.render({
                elem: '#logintime1' //指定元素
                ,type :"datetime"
            });

            laydate.render({
                elem: '#logintime2' //指定元素
                ,type :"datetime"
            });

            // 初始table
            logTable = table.render({
                elem:"#logTable"
                ,url:"/car/log/init"
                ,page: {limit:5 ,limits:[5,10,15]} //开启分页
                ,cellMinWidth:80
                ,toolbar: '#toolbarLog' //开启头部工具栏，并为其绑定左侧模板
                ,cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'}
                    ,{field: 'id', title: '日志ID',  fixed: 'center'}
                    ,{field: 'loginname', title: '登录名称',   fixed: 'center'}
                    ,{field: 'loginip', title: '登录IP',  fixed: 'center'}
                    ,{field: 'logintime', title: '登录时间',   fixed: 'center'}
                    ,{fixed: 'right', title:'操作', toolbar: '#barLog', width:280}
                ]]
            })

            // form表单提交  -- 查询功能
            form.on("submit(doSearch)",function(data) {
                logTable.reload({
                    url:"/car/log/init"
                    ,where :data.field
                    ,page:{
                        curr:1
                    }
                })
                return false;
            })

            // 头部工具栏添加事件
            table.on('toolbar(logTable)',function(obj) {
                if(obj.event == "delBatch"){
                var checkStatus = table.checkStatus(obj.config.id)//获取选中的条数
                    if(checkStatus.data.length==0){//选择的条数=0就提示
                        layer.msg("您至少选择一条进行删除")
                    }
                    var ids=new Array() //申明数组
                    for(var i=0;i<checkStatus.data.length;i++){
                          ids.push(checkStatus.data[i].id)//把选中条数的Id循环装进ids数组
                    }
                    $.post("/car/log/deleteAll",{"ids":ids},function (r) {//传ids到contorlle层进行批量删除
                        layer.msg(r.msg)
                        logTable.reload()
                    })
                }
            })

            //监听行工具事件
            table.on('tool(logTable)', function(obj){
                var data = obj.data
                  if(obj.event == "del"){ // 删除
                    del(data)
                }
            })

            function del(data){
                layer.confirm("您确定要删除该条日志吗",function (ind) {
                    $.post("/car/log/delete",{"id":data.id},function (r) {
                                layer.msg(r.msg)
                                logTable.reload()
                    })
                    layer.close(ind)
                })
            }


        });


    </script>
</body>
</html>
